/* Copyright (c) 2025 Huawei Technologies Co., Ltd.
* This file is a part of the CANN Open Software.
 * Licensed under CANN Open Software License Agreement Version 1.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 * ===================================================================================================================*/

#ifndef COMMON_H
#define COMMON_H
#include <cstdint>
#include <format>

#if defined(_MSC_VER)
  #if defined(_WIN64)
    #define BIT64
  #endif
#elif defined(__GNUC__)
  #if defined(__LP64__)
    #define BIT64
  #endif
#endif

namespace aclrec {
using Result = int64_t;

#if defined(BIT64)
  using DevAddr = void *;
#else
  #error "only support host in 64 bit mode"
#endif

using HostAddr = void *;
inline std::string FormatErrorString() {
  return "";
}
template <typename... Args>
std::string FormatErrorString(const std::string& format, Args&&... args) {
  return std::format(format, std::forward<Args>(args)...);
}
#define ASSERT(x, ...) do { \
    if (!(x)) { \
      auto error_string = FormatErrorString(__VA_ARGS__); \
      if (error_string.empty()) { \
        error_string = FormatErrorString("Assertion failed: " #x); \
      } \
      throw std::runtime_error(error_string); \
    } \
  } while (0)
#define ASSERT_ACL_SUCCESS(x, ...) ASSERT((x == ACL_SUCCESS), __VA_ARGS__)
constexpr uint32_t kInvalidModelId = 0xffffffff;
}
#endif //COMMON_H
